<?php
declare(strict_types=1);
namespace App\Dao;

use App\Constants\ErrorCode;
use App\Exception\BusinessException;
use App\Model\CouponStatistics as Model;
use App\Model\Coupon;

class CouponStatisticsDao {
    use DaoTrait;
    
    public function __construct()
    {
        $this->driver=__CLASS__;    
    }


    /**
     * 根据分页与条件查询数据
     * @Author czm
     * @DateTime 2020-05-26
     * @param array $map
     * @param array $page
     * @param array $fields
     * @return void
     */
    public function pageByWhere($map = [], $page = [], $fields = [], $scope = [])
    {
        $model = Model::query();
        if (!empty($fields)) {
            $model->select($fields);
        }
        $model = $model->when(!empty($map), function ($query) use ($map) {
            $query->where($map);
        });
        $count = $model->count();
        $data = $model->orderBy('id', 'desc')->paginate(intval($page['pageSize']),['*'],'page',$page['page'])->toArray()['data'];
        return compact('count', 'data');
    }

}